package pddxueba;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created by JiaJia on 2019/7/28 0028.
 */
public class Flag {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        List<String> list=new ArrayList<>();
        while (scanner.hasNext()){
            list.add(scanner.next());
        }
        boolean valid=true;
        int count=0;
        for (int i = 0; i <list.size() ; i++) {
            String str1=list.get(i);
            int next=i+1;
/*
            if (next==list.size()){
                next=0;
            }
            String str2=list.get(next);
            if (str1.charAt(str1.length()-1)!=str2.charAt(0))
                valid=false;

        }*/
            while (next!=i){
                String str2=list.get(next);
                if (str1.charAt(str1.length()-1)==str2.charAt(0))
                    count++;
                if (next==list.size()){
                    next=0;
                }
                next++;
            }
            }
        if (count<list.size()){
            valid=false;
        }
        System.out.println(valid);
        }

    }

